package main

import (
	"context"
	"fmt"
	"time"
)

func main()  {
	ctx, cancel:= context.WithTimeout(context.Background(), time.Second * 10)
	defer cancel()
	worker(ctx)
}

func worker(ctx context.Context)  {
	for {
		select {
		case <-ctx.Done():
			fmt.Println("I am done")
			return
		case <-time.After(time.Second * 3):
			fmt.Println("over time")
			return
		default:
			fmt.Println("I am handsome")
			time.Sleep(time.Second * 1)
		}
	}
}